#include "RingQueue.hpp"

void *Producter(void *args)
{

    cout << "生产者故意休眠3s" << endl;
    sleep(3);

    RingQueue<int> *rq = (RingQueue<int> *)args;
    int count = 100;
    while (1)
    {
        rq->Push(count);
        cout << "Producter data: " << count <<", flag is: "<< rq->GetProducterFlag()<< endl;
        count--;
    }
}
void *Consumer(void *args)
{
    RingQueue<int> *rq = (RingQueue<int> *)args;
    int data = 0;
    while (1)
    {

        sleep(1);
        rq->Pop(&data);
        cout << "Consumer data: " << data << endl;
    }
}
void test1()
{
    pthread_t p[2], c[2];
    RingQueue<int> *rq = new RingQueue<int>();
    pthread_create(&p[0], nullptr, Producter, rq);
    pthread_create(&p[1], nullptr, Producter, rq);
    pthread_create(&c[0], nullptr, Consumer, rq);
    pthread_create(&c[1], nullptr, Consumer, rq);

    pthread_join(p[0], nullptr);
    pthread_join(p[1], nullptr);
    pthread_join(c[0], nullptr);
    pthread_join(c[1], nullptr);
}
int main()
{
    test1();
}